home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1996 April / MacFormat CD Edition MF36 (April 1996).iso / Shareware City / Developers / Tools Plus - GUI⁄Event libs / Tools Plus 2.6.1a Evaluat'n Kit / Tools Plus 2.6.1a / Tutorials / 5-Pop-Up Menus / Tutorial.p < prev    next >
Text File  |  1995-08-25  |  4KB  |  133 lines

  1. {    Tools Plus Tutorial    - -    Pop-Up Menus    }
  2.  
  3. {    NOTE:    }
  4. {    The MWERKS compiler directived ($IFC MWERKS) indicates code that is compiled only by    }
  5. {    the CodeWarrior compiler.  THINK Pascal and Metrowerks CodeWarrior Pascal have    }
  6. {    _slight_ differences, and this compiler directive lets you use one source for both compilers.    }
  7. {    You can remove the code that does not pertain to your compiler.    }
  8.  
  9.  
  10. program Tutorial;
  11.     uses
  12. {$IFC MWERKS}
  13.         Dialogs, Fonts, Processes, SegLoad, TextEdit, ToolsPlus, Windows;
  14. {$ELSEC}
  15.         ToolsPlus;
  16. {$ENDC}
  17.  
  18.  
  19.     const
  20.     { Pop-up menu constants for more readable code… }
  21.         ordinaryPopUp = 1;
  22.         popDownMenu = 2;
  23.         littlePopUp = 3;
  24.  
  25.         DoneButton = 255;
  26.  
  27.  
  28.     var
  29.         Poll: TPPollRecord;            {Polling record to retrieve event information}
  30.         ExitTheDemo: boolean;        {Should the demo terminate?}
  31.  
  32.         theButton: integer;            {Button number clicked in an alert }
  33.  
  34.  
  35.  
  36.  
  37.  
  38. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  39.     procedure ApplicationInitialization;
  40.         const
  41.             DemoWindow1 = 1;
  42.     begin
  43.     {    Do all the application setup before you start polling for events…    }
  44.  
  45.         WindowOpen(DemoWindow1, 0, 0, 225, 170, '', dBoxProc + wCenter, noGoAway, Modal);
  46.  
  47.  
  48.     { Create a Pop-Up Menu that hides the 'down arrow'.}
  49.     { The pop-up menu is populated with icons.  Note that the Menu Manager adds 256 to the icon specifier    }
  50.     { (the number following the '^' mark).  Example: ^44 +  256 = 300, or 'cicn' resource ID 300 is used.    }
  51.         NewPopUp(ordinaryPopUp, 100, 20, 206, 20, 'Search Here:', popupIconTitle + popupNoArrow, enabled);
  52.         PopUpMenu(ordinaryPopUp, 1, enabled, 'Desktop^44');
  53.         PopUpMenu(ordinaryPopUp, 2, enabled, 'Hard Disk^45');
  54.         PopUpMenu(ordinaryPopUp, 3, enabled, 'Tools Plus^46');
  55.         PopUpMenu(ordinaryPopUp, 4, enabled, 'THINK C^47');
  56.         PopUpMenu(ordinaryPopUp, 5, enabled, 'Libraries^47');
  57.         PopUpMenu(ordinaryPopUp, 6, enabled, '#Includes^47');
  58.         CheckPopUp(ordinaryPopUp, 1, on);    {Select first item by placing a check mark beside it}
  59.  
  60.  
  61.     { Create a 'pull-down' menu with a fixed title inside the control…}
  62.         NewPopUp(popDownMenu, 100, 50, 206, 50, 'Format', popupFixedTitle, enabled);
  63.         PopUpMenu(popDownMenu, 1, enabled, 'Clear');
  64.         PopUpMenu(popDownMenu, 2, enabled, 'Paragraph…');
  65.         PopUpMenu(popDownMenu, 3, enabled, 'Character…');
  66.         PopUpMenu(popDownMenu, 4, enabled, 'Style…');
  67.  
  68.  
  69.     { Create a pop-up menu using Geneva 9pt…}
  70.         TextFont(Geneva);
  71.         TextSize(9);
  72.         NewPopUp(littlePopUp, 100, 80, 133, 80, 'Size:', popupUseWFont + popupNoArrow, enabled);
  73.         PopUpMenu(littlePopUp, 1, enabled, '9');
  74.         PopUpMenu(littlePopUp, 2, enabled, '10');
  75.         PopUpMenu(littlePopUp, 3, enabled, '12!•');    { This item is selected by being marked with a bulled (•) }
  76.         PopUpMenu(littlePopUp, 4, enabled, '14');
  77.         PopUpMenu(littlePopUp, 5, enabled, '18');
  78.         PopUpMenu(littlePopUp, 6, enabled, '24');
  79.         PopUpMenu(littlePopUp, 7, enabled, '36');
  80.  
  81.  
  82.         NewButton(DoneButton, 85, 130, 140, 150, 'Done', pushButProc + DefaultButton, enabled, notSelected);
  83.         ExitTheDemo := false;
  84.     end;
  85.  
  86.  
  87. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  88. begin
  89. {$IFC MWERKS}
  90. {Toolbox initialization - - Done automatically by THINK Pascal}
  91.     InitGraf(@qd.thePort);
  92.     InitFonts;
  93.     InitWindows;
  94.     InitMenus;
  95.     TEInit;
  96.     InitDialogs(nil);
  97.     MaxApplZone;
  98. {$ENDC}
  99.  
  100.     if not InitToolsPlus(0, 1, UseColor) then
  101.         ExitToShell;
  102.  
  103.     ApplicationInitialization;
  104.  
  105.     while not ExitTheDemo do    {Main Event Loop}
  106.         if PollSystem(Poll) then    {If an event is available, process the event…}
  107.  
  108.             case Poll.What of
  109.  
  110.                 doButton:    {User clicked a button ('Done' is the only button we have)… }
  111.                     ExitTheDemo := true;
  112.  
  113.                 doPopUpMenu: 
  114.                     case Poll.Menu.Num of
  115.                         ordinaryPopUp:
  116.                 { Put check mark (√) beside selected item. Previously selected item is    }
  117.                 {    automatically deselected (this feature is optional).}
  118.                             CheckPopUp(Poll.Menu.Num, Poll.Menu.Item, on);
  119.  
  120.                         popDownMenu:
  121.                 { Your app would likely execute a process here… }
  122.                             theButton := AlertBox(noteIcon, 'Your application would do something now.', -OkAlert);
  123.  
  124.                         littlePopUp:
  125.                 { Put bullet (•) beside selected item. Previously selected item is    }
  126.                 {    automatically deselected (this feature is optional).}
  127.                             PopUpMark(Poll.Menu.Num, Poll.Menu.Item, DotChar);
  128.                     end;
  129.  
  130.  
  131.                 otherwise    {All other events are ignored}
  132.             end
  133. end.